﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ToracTechnologies.ExpressionTreeLibrary.ExtensionMethods.IEnumerable;
using ToracTechnologies.ExpressionTreeLibrary.ExtensionMethods.Strings;

namespace ToracTechnologies.ExpressionTree.Testing.ExtensionMethods.IEnumerable
{
    [TestClass]
    public class IEnumerableExtensionMethodsUnitTest
    {

        [TestMethod]
        public void AnyWithNullCheck_Test1()
        {
            List<int> lst = null;

            Assert.AreEqual(false, lst.AnyWithNullCheck());

            lst = new List<int>();

            Assert.AreEqual(false, lst.AnyWithNullCheck());

            lst.Add(1);

            Assert.AreEqual(true, lst.AnyWithNullCheck());

            lst.Add(2);
            Assert.AreEqual(true, lst.AnyWithNullCheck());

            lst.Clear();

            Assert.AreEqual(false, lst.AnyWithNullCheck());
        }

        [TestMethod]
        public void AnyWithNullCheckPredicate_Test1()
        {
            List<int> lst = null;

            Assert.AreEqual(false, lst.AnyWithNullCheck(x => x == 5));

            lst = new List<int>();

            Assert.AreEqual(false, lst.AnyWithNullCheck(x => x == 5));

            lst.Add(1);

            Assert.AreEqual(true, lst.AnyWithNullCheck(x => x == 1));
            Assert.AreEqual(false, lst.AnyWithNullCheck(x => x > 5));

            lst.Add(2);
            Assert.AreEqual(true, lst.AnyWithNullCheck(x => x == 2));
            Assert.AreEqual(false, lst.AnyWithNullCheck(x => x > 5));

            lst.Clear();

            Assert.AreEqual(false, lst.AnyWithNullCheck(x => x <= 5));
        }

    }
}
